1、机器人运动范围
思想：标准的dfs   这种题目首先明白当前干什么，然后接下来干什么，以及注意退出条件
class Solution {
public:
    //坐标数组
    int nextp[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
    int sum(int n)
    {
        int s=0;
        while(n)
        {
            s+=(n%10);
            n/=10;
        }
        return s;
    }
    void dfs(int threshold, int rows, int cols,int curx,int cury,vector<vector<int>>& book,int& count)
    {
       
        book[curx][cury]=1;
        count+=1;
        //遍历某个坐标的上下左右
        for(int i=0;i<4;i++)
        {
            int newx=curx+nextp[i][0];
            int newy=cury+nextp[i][1];
            if(newx<0||newx>=rows||newy<0||newy>=cols||book[newx][newy]==1||(sum(newx)+sum(newy))>threshold)
                continue;
            else
                dfs(threshold,rows,cols,newx,newy,book,count);
        }
    }
    int movingCount(int threshold, int rows, int cols) {
        int count=0;
        vector<vector<int>> book(rows,vector<int>(cols,0));
        dfs(threshold,rows,cols,0,0,book,count);
        return count;
    }
};